﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;

namespace WikiDialogFix
{
    public class WikiDialogFixDelegateControl : Control
    {
        protected override void OnPreRender(EventArgs e)
        {
            Page currentPage = this.Page;
            SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
            SPContext context = SPContext.Current;

            if (context.IsPopUI)
            {
                if (currentPage.GetType().BaseType == typeof(WikiEditPage))
                    // OK, not elegant... Feel free to modify.
                {
                    ribbon.MakeTabAvailable(SPRibbon.ReadTabId);
                    
                    // Uncomment the line below if you want to hide Browse tab.
                    //ribbon.TrimById(SPRibbon.ReadTabId);
                }
            }

        }
    }
}
